<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h1>{{msg}}</h1>

      <button @click='updateData'>点击更改数据</button>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
         //创建 new  Vue() 系统自动在某个节点帮你执行这些钩子函数

      var vm = new Vue({
        el: "#app",
        data: {
          msg: "vue",
          list:['node']
        },
        beforeCreate(){
            console.log('beforeCreate');

        },
        created() { // data数据加载了 
            console.log('created');
        },
        beforeMount() {
          console.log('beforeMount');

          console.log('beforeMount',this.$el);
        },
        mounted() {
          console.log('mounted');
          console.log('mounted'.this.$el);
        },
        beforeUpdate() {
            console.log('beforeUpdate');
        },
        updated() {
            console.log('updated');
        },
        beforeDestroy() {
            console.log('beforeDestroy');
        },
        destroyed() {
            console.log('destroyed');
        },
        methods: {
            updateData() {
                this.msg='我被改变了'
            },
        },
      });
      setTimeout(()=>{
          alert('5s后我被执行了')
          vm.$destroy()
      },5000)
    </script>
  </body>
</html>
